package com.action.school;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.action.base.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.pageModel.Json;
import com.pageModel.Special;
import com.service.school.SpecialServiceI;

/**
 * 特殊校友ACTION
 * 
 * @author chenq
 * 
 */

@Namespace("/school")
@Action(value = "specialAction")
public class SpecialAction extends BaseAction implements ModelDriven<Special>{

	Special special=new Special();
	
	@Override
	public Special getModel() {
		return special;
	}

	private SpecialServiceI SpecialService;

	public SpecialServiceI getSpecialService() {
		return SpecialService;
	}
	@Autowired
	public void setSpecialService(SpecialServiceI specialService) {
		SpecialService = specialService;
	}
	
	public void datagrid() {
		super.writeJson(SpecialService.datagrid(special));
	}
	
	public void edit_TG(){
		SpecialService.edit_TG(special);
		Json j=new Json();
		j.setSuccess(true);
		j.setMsg("修改成功！");
		super.writeJson(j);
	}
	
	public void edit_BTG(){
		SpecialService.edit_BTG(special);
		Json j=new Json();
		j.setSuccess(true);
		j.setMsg("修改成功！");
		super.writeJson(j);
	}
	public void add(){
		String json = null;
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			SpecialService.add(special);
			m.put("success", true);
			m.put("msg", "添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
			m.put("success", false);
			m.put("msg", "添加失败！");
			System.out.print(e.getMessage());
		}
		super.writeJson(m);
	}
	
	public void getSpecialCmb(){
		super.writeJson(SpecialService.getSpecialCmb(special));
	}
}
